// pages/my/examRule/examRule.js
const { httpPost, httpGet } = require('../../common/js/http')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    second: 5,
    toPageVal: 0,
    nums: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderExamId: options.orderExamId
      // orderExamId: '110'
    })
  },
  topage(){
    // wx.redirectTo({
    wx.navigateTo({
      url: '../exam/exam?orderExamId='+ this.data.orderExamId,
    })
  },
  topage2() {
    if(this.data.examType == 1){
      wx.navigateTo({
        url: '../../report/zyysl/zyysl?orderExamId=' + this.data.orderExamId
      })
      return
    }else{
      wx.navigateTo({
        url: '../../report/zydj/zydj?orderExamId=' + this.data.orderExamId
      })
      return
    }
  },
  getStatus(orderExamId) {
    httpGet({
      url: "/app/orderExam/admin/getOrderExamDetail",
      data: {orderExamId,isNeedTitles: 1},
      isLoding: true,
      lodingMsg: '加载中...'
    }).then(res => {
      if(res.errorCode == 0){
        if(res.data.orderExamStatus == 2) {
          //已完成答题
          this.setData({
            toPageVal: 2,
            examType: res.data.examType,
            second: 0
          })
        } else {
          //未完成答题
          this.setData({
            toPageVal: 1,
            examType: res.data.examType
          })
          let time = 5;
          let timer = setInterval(res => {
            time-- 
            if(time == 0){
              clearInterval(timer)
            }
            this.setData({
              second: time
            })
          },1000)
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getStatus(this.data.orderExamId)
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})